using System;
using System.Collections.Generic;
using System.Text;
using PDSClient.Utils.Shared;

namespace PDSClient.Simple.Impl
{
    class SimpleSessionId : SessionId
    {
        private byte[] id; //was final

        private CompactId compactId;

        public SimpleSessionId(byte[] id)
        {
            if (id == null)
                throw new NullReferenceException("id must not be null");

            this.compactId = new CompactId(id);
            this.id = compactId.Id;
        }

        public override byte[] ToBytes()
        {
            return id;
        }

        public override bool Equals(object obj)
        {
            if (this == obj)
                return true;

            return (obj is SessionId && Array.Equals(id, (((SessionId)obj).ToBytes())));
        }

        public override int GetHashCode()
        {
            return id.GetHashCode();
        }

        public override string ToString()
        {
            return GetType().Name + "@" + Convert.ToString(id);
        }
        public CompactId CompactId { get { return compactId; } }
    }
}
